var gl_userVipCard_vue_vm_list = $('#userVipCard_vue_vm_list').html();

$(function() {
	$('#userVipCard_vue_vm_list div').hide();
});

function findUserVipCard() {
	if($('#userVipCard_vue_vm_list').length==0) {return;}
	$('#userVipCard_vue_vm_list div').hide();
	var searchVal = $('#userVipCard_searchVal').val();
	if(searchVal=='') {
		alert('请先输入持卡者姓名或身份证');
		return;
	}
	
	openWaiting('正在查找');
	find_basic_by_json(path+'/userVipCard/find', {searchVal: searchVal}, function(response) {
		$('#userVipCard_vue_vm_list').html(gl_userVipCard_vue_vm_list);
		
		for(var i=0; i<response.data.length; i++) {
			response.data[i].index = i+1;
		}
		
		new Vue({
			el: '#userVipCard_vue_vm_list',
			data: {
				todos: response.data
			},
			methods: {
				onClickUserVipCardRadiobox:function(todo) {
					var userVipCardId = $('input:radio[name="userVipCardId"]:checked').val();
					if(userVipCardId==todo.userVipCardId) {
						view.data.userVipCardId = todo.userVipCardId;
						view.data.vipCardRelation = todo.name;
						view.data.vipCardId = todo.vipCardId;
						view.data.vipCardName = todo.vipCardName;
						view.data.houseTypeId = todo.houseTypeId;
						view.data.houseTypeName = todo.houseTypeName;
					}
				},
				onClickUserVipCardRadiobox02:function(todo) {
					var userVipCardId = $('input:radio[name="userVipCardId"]:checked').val();
					if(userVipCardId==todo.userVipCardId) {
						view.data = cloneJson(todo);
						view.data.userVipCardId = todo.userVipCardId;
						view.data.vipCardRelation = todo.name;
						view.data.vipCardId = todo.vipCardId;
						view.data.vipCardName = todo.vipCardName;
						view.data.houseTypeId = todo.houseTypeId;
						view.data.houseTypeName = todo.houseTypeName;
					}
				},
				getSubsidizationValue:function(subsidization, subsidizationValue) {
					return subsidization=='无补助'? '': subsidizationValue;
				},
				getSubsidizationUnit:function(subsidization) {
					return subsidization=='饭卡补助'? '元': (subsidization=='包餐补助'?'天':'');
				},
				getSubsidizationText:function(subsidization, subsidizationValue) {
					return subsidization + this.getSubsidizationValue(subsidization, subsidizationValue) + this.getSubsidizationUnit(subsidization);
				},
				//总共可扣月数
				getTotalMonths:function(todo) {
					return 12 * parseInt(todo.durableYears);
				},
				//剩余可扣月数
				getRemainMonths:function(todo) {
					return todo.surplusMonths;
				},
				//已扣月数
				getAlreadyUsedMonths:function(todo) {
					var alreadyUsedMonths = this.getTotalMonths(todo) - this.getRemainMonths(todo);
					return alreadyUsedMonths;
				},
				//总共可扣天数
				getTotalNumber:function(todo) {
					/*
					if(todo.consumptionWay=='半个月扣费') {
						return 24 * parseInt(todo.durableYears);
					}else {
						return 12 * parseInt(todo.durableYears);
					}
					*/
					
					return 365 * parseInt(todo.durableYears);
				},
				//剩余可扣天数
				getRemainNumber:function(todo) {
					return todo.buckleNumber;
				},
				//已扣天数
				getAlreadyUsedNumber:function(todo) {
					var alreadyUsedNumber = todo.deductNumber;
					return alreadyUsedNumber;
				}
				
			}
		});
		
		$('#userVipCard_vue_vm_list div').show();
		closeWaiting();
	});
}